package com.aust.state;

/**
 * 测试线程优先级
 */
public class TestPriority {

    public static void main(String[] args) {
        /**
         * 主线程优先级
         */
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());

        MyPriority myPriority = new MyPriority();
        Thread t1 = new Thread(myPriority);
        Thread t2 = new Thread(myPriority);
        Thread t3 = new Thread(myPriority);
        Thread t4 = new Thread(myPriority);
        Thread t5 = new Thread(myPriority);
        Thread t6 = new Thread(myPriority);

        /**
         * 设置优先级并启动
         */
        t2.setPriority(1);
        t3.setPriority(4);
        t4.setPriority(Thread.MAX_PRIORITY); // MAX_PRIORITY=10
        t5.setPriority(8);
        t6.setPriority(6);

        t1.start(); // 0
        t2.start(); // 1
        t3.start(); // 2
        t4.start(); // 3
        t5.start(); // 4
        t6.start(); // 5

    }

}

class MyPriority implements Runnable {
    @Override
    public void run() {
        /**
         * 次线程优先级
         */
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
    }
}
